import { Form, Input, InputNumber, Select } from 'antd';
import { useState } from 'react';
import an58 from '@mmstudio/an000058';
import AddButton from '../../../components/addbutton';
import api from '../../../atoms/api';
import { Message as M1, Result as R1 } from '../../api/project/add.api';
import Uploader from '../../../components/uploader';

export default function Add({ team }: {
	team: Pick<ITbteam, 'classname' | 'class_id' | 'team_id' | 'teamname' | 'grade'>[];
}) {
	const [d, setd] = useState({} as M1);
	const [t, sett] = useState({} as ITbteam[]);
	return <>
		<AddButton dlgtitle='新增' onSave={async () => {
			if (!d
				|| !d.teammate
				|| !d.teamname
			) {
				return '缺少必要的参数';
			}
			const res = await an58<R1, M1>(api['/api/project/add'], 'post', d);
			if (res.ok === true) {
				return true;
			}
			return res.message;
		}}>
			<Form.Item required label="年级:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择年级'
					value={d.grade}
					onChange={(e) => {
						setd({
							...d,
							grade: e
						});
					}} >
					{team.map((it) => {
						return <Select.Option key={it.grade} value={it.grade} >{it.grade}</Select.Option>;
					})}
				</Select></Form.Item>
			{/* <Form.Item required label="班级名称:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择班级名称'
					value={d.classnumber}
					onChange={(e) => {
						setd({
							...d,
							classnumber: e
						});
					}} >
					{team.map((it) => {
						return <Select.Option key={it.classnumber} value={it.classnumber} >{it.classnumber}</Select.Option>;
					})}
				</Select></Form.Item>
			<Form.Item required label="团队编号:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择团队编号'
					value={d.teamnumber}
					onChange={(e) => {
						setd({
							...d,
							teamnumber: e
						});
					}} >
					{team.map((it) => {
						return <Select.Option key={it.teamnumber} value={it.teamnumber} >{it.teamnumber}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="项目名称:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择项目名称'
					value={d.projectnumber}
					onChange={(e) => {
						setd({
							...d,
							projectnumber: e
						});
					}} >
					{project.map((it) => {
						return <Select.Option key={it.projectnumber} value={it.projectnumber} >{it.projectname}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="团队名称:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择团队名称'
					value={d.teamname}
					onChange={(e) => {
						setd({
							...d,
							teamname: e
						});
					}} >
					{team.map((it) => {
						return <Select.Option key={it.teamname} value={it.teamname} >{it.teamname}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="项目负责人:">
				<Input placeholder='请输入项目负责人' value={d.projectleader} onChange={(e) => {
					setd({
						...d,
						projectleader: e.target.value
					});
				}} />
			</Form.Item> */}
			<Form.Item required label="项目简介:">
				<Input.TextArea rows={4} placeholder='请输入项目简介' value={d.projectintroduction} onChange={(e) => {
					setd({
						...d,
						projectintroduction: e.target.value
					});
				}} />
			</Form.Item>
			<Form.Item required label="项目路演视频:">
				{d.roadshowvideo && <video src={d.roadshowvideo}></video>}
				<Uploader type='video' multiple={false} onChange={(file) => {
					setd({
						...d,
						roadshowvideo: file
					});
				}} />
			</Form.Item>
			<Form.Item required label="项目路演文件:">
				{d.roadshowdocuments && <a target='_blank' href={d.roadshowdocuments} rel="noreferrer">打开</a>}
				<Uploader type='ppt' multiple={false} onChange={(file) => {
					setd({
						...d,
						roadshowdocuments: file
					});
				}} />
			</Form.Item><br></br>
			<Form.Item required label="项目计划书:">
				{d.prospectus && <a target='_blank' href={d.prospectus} rel="noreferrer">打开</a>}
				<Uploader type='pdf' multiple={false} onChange={(file) => {
					setd({
						...d,
						prospectus: file
					});
				}} />
			</Form.Item>
		</AddButton>
	</>;
}
